<!DOCTYPE HTML>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<link th:href="@{/ajax/libs/jquery-layout/jquery.layout-latest.css}" rel="stylesheet"/>
<link th:href="@{/ajax/libs/jquery-ztree/3.5/css/metro/zTreeStyle.css}" rel="stylesheet"/>
<style>
	.requiredData-success {
		color: #fff;
		background: #5cb85c;
	}
	.requiredData-default {
		color: #000;
		background: #eeeeee;
	}
	.bootstrap-tree-table .treetable-table tbody,.bootstrap-tree-table .treetable-tbody td{
		overflow: visible;
	}

</style>
<body class="gray-bg">
<div class="ui-layout-west">
	<div class="main-content">
		<div class="box box-main">
			<div class="box-header">
				<div class="box-title">
					<i class="fa icon-grid"></i> 接口项目
				</div>
				<div class="box-tools pull-right">
					<a type="button" class="btn btn-box-tool menuItem" href="#" onclick="apiview()" title="接口查看打开"><i class="fa fa-link"></i></a>
					<a type="button" class="btn btn-box-tool menuItem" href="#" onclick="project()" title="接口项目编辑"><i class="fa fa-edit"></i></a>
					<button type="button" class="btn btn-box-tool" id="btnExpand" title="展开" style="display:none;"><i class="fa fa-chevron-up"></i></button>
					<button type="button" class="btn btn-box-tool" id="btnCollapse" title="折叠"><i class="fa fa-chevron-down"></i></button>
					<button type="button" class="btn btn-box-tool" id="btnRefresh" title="刷新部门"><i class="fa fa-refresh"></i></button>
				</div>
			</div>
			<div class="ui-layout-content">
				<div id="tree" class="ztree"></div>
			</div>
		</div>
	</div>
</div>
<div class="container-div ui-layout-center">
	<div class="row">
		<div class="col-sm-12 select-info">
			<form id="connector-form">
				<input type="hidden" id="apiProjectnameId" name="apiProjectnameId">
				<input type="hidden" id="parentId" name="parentId">
				<div class="select-list">
					<ul>
						<li>
							接口名称：<input type="text" name="interfacename"/>
						</li>
						<li>
							接口描述：<input type="text" name="description"/>
						</li>
						<li>
							&nbsp;&nbsp;&nbsp;&nbsp;创建人：<input type="text" name="createBy"/>
						</li>
						<li class="select-time">
							<label>创建时间： </label>
							<input type="text" class="time-input" id="startTime" placeholder="开始时间" name="params[beginTime]"/>
							<span>-</span>
							<input type="text" class="time-input" id="endTime" placeholder="结束时间" name="params[endTime]"/>
						</li>
						<li>
							<a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
							<!--<a class="btn btn-success btn-rounded btn-sm" onclick="$.table.exportExcel()" shiro:hasPermission="system:user:export"><i class="fa fa-download"></i>&nbsp;导出</a>-->
						</li>
					</ul>
				</div>
			</form>
		</div>
		<div class="btn-group hidden-xs" id="toolbar" role="group">
			<a class="btn btn-outline btn-success btn-rounded" onclick="addConnector()" shiro:hasPermission="module:connector:add">
				<i class="fa fa-plus"></i> 新增接口
			</a>
		</div>

		<div class="col-sm-12 select-table ">
			<table id="bootstrap-table" data-mobile-responsive="true" style="white-space:nowrap;"></table>
		</div>



		<form id="parameter_form" >
			<input type="hidden" id="apiProjectnameId_parameter" name="apiProjectnameId">
			<input type="hidden" id="parentId_parameter" name="parentId">
		</form>

		<div class="btn-group hidden-xs" id="toolbar_parameter" role="group">
			<a class="btn btn-outline btn-success btn-rounded" onclick="addParameter()" shiro:hasPermission="module:connector:add">
				<i class="fa fa-plus"></i> 新增请求参数
			</a>
			<a class="btn btn-outline btn-success btn-rounded" onclick="copyParameter()" shiro:hasPermission="module:connector:add">
				<i class="fa fa-copy"></i> 复制请求参数
			</a>
		</div>
		<div class="col-sm-12 select-table ">
			<table id="bootstrap_table_parameter" data-mobile-responsive="true" style="white-space:nowrap;"></table>
		</div>

		<form id="response_form" >
			<input type="hidden" id="apiProjectnameId_response" name="apiProjectId">
			<input type="hidden" id="parentId_response" name="parentIdResponse">
		</form>

		<div class="btn-group hidden-xs" id="toolbar_response" role="group">
			<a class="btn btn-outline btn-success btn-rounded" onclick="addNewResponse(null)" shiro:hasPermission="module:connector:add">
				<i class="fa fa-plus"></i> 新增返回参数
			</a>
			<a class="btn btn-outline btn-success btn-rounded" onclick="addResponse()" shiro:hasPermission="module:connector:add">
				<i class="fa fa-upload"></i> json导入
			</a>
            <a class="btn btn-outline btn-danger btn-rounded" onclick="cleanResponse()" shiro:hasPermission="module:connector:add">
                <i class="fa fa-trash"></i> 清空
            </a>
		</div>
		<div class="col-sm-12 select-table ">
			<table id="bootstrap_table_response" data-mobile-responsive="true" style="white-space:nowrap;"></table>
		</div>

		<form id="errorcode_form" >
			<input type="hidden" id="apiProjectnameId_errorcode" name="apiProjectnameId">
			<input type="hidden" id="parentId_errorcode" name="parentId">
		</form>


		<div class="row col-sm-12" id="toolbar_errorcode" style="width: 400px">
			<div class="col-md-9 btn-group hidden-xs" role="group">
				<a class="btn btn-outline btn-success btn-rounded" onclick="addErrorcode()" shiro:hasPermission="module:connector:add">
					<i class="fa fa-plus"></i> 新增错误代码
				</a>
			</div>

			<div class="col-md-3">
				<label id="errorGroup" align="left"  style="white-space:nowrap">

				</label>
			</div>
		</div>
		<div class="col-sm-12 select-table ">
			<table id="bootstrap_table_errorcode" data-mobile-responsive="true" style="white-space:nowrap;"></table>
		</div>
	</div>
</div>
	<div th:include="include :: footer"></div>
<script th:src="@{/ajax/libs/jquery-layout/jquery.layout-latest.js}"></script>
<script th:src="@{/ajax/libs/bootstrap3-editable/js/bootstrap-editable.js}"></script>
<script th:src="@{/ajax/libs/jquery-ztree/3.5/js/jquery.ztree.all-3.5.js}"></script>

<script th:src="@{/snow/js/snow-bootstrap.js}"></script>

    <script th:inline="javascript">
        var errorGroup=0;
        var editFlag = [[${@permission.hasPermi('module:connector:edit')}]];
        var removeFlag = [[${@permission.hasPermi('module:connector:remove')}]];
        var prefix = ctx + "module/connector";
        var prefix_errorcode = ctx + "module/errorcode";
        var prefix_parameter = ctx + "module/parameter";
        var prefix_response = ctx + "module/response";

        var methodDatas = [[${@dict.getType('api_http_method')}]];
        var valueTypeDatas = [[${@dict.getType('api_value_type')}]];
        var responseValueTypeDatas = [[${@dict.getType('response_value_type')}]];
        var paramTransmissionMode = [[${@dict.getType('param_transmission_mode')}]];

        var requiredDatas = [{"dictLabel":"√","dictValue":"1","listClass":"success"},
            {"dictLabel":"×","dictValue":"0","listClass":"default"}];

        var treeTableResponse;

        var newResponseId = 0;

        $(function() {
            $('body').layout({ west__size: 185 });
            queryConnectorList();
            queryProjectTree();
            queryErrorcodeList();
            queryParameterList();
            queryResponseList();
        });
        
        function detailChange(event,id) {
            //判断是不是 textarea
            if($(event)[0].tagName.toLowerCase()=="textarea"){

			}
            var value=$(event).val();
            $("#"+id).val(value);

			
        }

        function saveResponse(id,event,textareaId){
            var url =   prefix_response + "/update";
            $.modal.loading("正在处理中，请稍后...");

			var $_event = $(event).parent().prev();
			var postValue;
			if(textareaId==undefined){
                postValue= $_event.val();
            }else{
			    postValue=$("#"+textareaId).val();
			}
            var data = {value:postValue,responseId:id,modifyField:$_event.attr("name")};
            var config = {
                url: url,
                type: "post",
				data: data,
                success: function(result) {
                    $.operate.ajaxSuccess(result);
                    // searchResponse();
                }
            };
            $.ajax(config)
		}
		//https://www.cnblogs.com/xiaoleiel/p/8308774.html
        function html_encode(str)
        {
			if($.common.isEmpty(str)){
			    return "";
			}
            var s = "";
            if (str.length == 0) return "";
            s = str.replace(/&/g, "&amp;");
            s = s.replace(/</g, "&lt;");
            s = s.replace(/>/g, "&gt;");
            s = s.replace(/ /g, "&nbsp;");
            s = s.replace(/\'/g, "&#39;");
            s = s.replace(/\"/g, "&quot;");
            // s = s.replace(/\n/g, "");
            s = s.replace(/\n/g, "&#10;");
            return s;
        }

        function getResponseInput(value,id,name,showDetail) {
            if(showDetail==undefined||showDetail==false){
                return '<div class="input-group">' +
                    '      <input type="text" class="form-control" placeholder="add value" value="'+(value == null ? "" : value)+'" name="'+name+'">' +
                    '      <span class="input-group-btn">' +
                    '        <button class="btn btn-success btn-xs" type="button" onclick="saveResponse('+id+',this)"><i class="fa fa-check"></i></button>' +
                    '      </span>' +
                    '    </div>';
			}
            var inputId=Math.uuid();
            var textareaId=Math.uuid();
			console.log("aa")
            var valueTemp=(value);
			var valueTemp2=value;

            if($.common.isEmpty(value)){
                valueTemp="";
                valueTemp2="";
            }else{
                //valueTemp2=$("<div/>").val(value).html;
			}

            valueTemp=html_encode(value);

            console.log("valueTemp=",valueTemp);

            return '<div class="input-group">' +
                '      <input readonly type="text" id="'+ inputId+'" class="form-control"  data-toggle="dropdown" placeholder="add value" value="'+valueTemp +'" name="'+name+'">' +
                '      <span class="input-group-btn">' +
                '        <button class="btn btn-success btn-xs" type="button" onclick="saveResponse('+id+',this,\''+textareaId+'\')"><i class="fa fa-check"></i></button>' +
                '      </span>' +
                '  <ul class="dropdown-menu"> ' +
                '      <textarea wrap="hard" id="'+ textareaId+'" class="form-control" name="'+name+'" rows="6" oninput="detailChange(this, \''+inputId+'\')" style="width: 300px">'+(valueTemp2)+'</textarea>'+
                ' </ul>'+
                '    </div>';
        }


        function addNewResponse(code){
            newResponseId = newResponseId+$("#bootstrap_table_response").find("tr").length+2;
            $('#bootstrap_table_response').append('<tr id="row_new_id_'+newResponseId+'" name="'+newResponseId+'" parent_code="'+code+'" pid="row_root" style="display: table;">' +
				'<td title="149" name="responseId" style="text-align:center;"><span class="treetable-expander"></span></td><td style="text-align:center;"><div class="input-group"> ' +
				'     <input type="text" class="form-control" placeholder="add value" value="" name="ParamName">      <span class="input-group-btn">    ' +
				'    <button class="btn btn-success" type="button" onclick=""><i class="fa fa-check"></i></button>      </span>  ' +
				'  </div></td><td style="text-align:center;"><div class="input-group">      <input type="text" class="form-control" placeholder="add value" value="" name="ParamDesc">   ' +
				'   <span class="input-group-btn">        <button class="btn btn-success" type="button" onclick="">' +
				'<i class="fa fa-check"></i></button>      </span>    </div></td><td style="text-align:center;"><div class="btn-group">  ' +
				' <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" name="ParamType" value="0"> 字符串 ' +
				'</button>  <ul class="dropdown-menu">  <li><a href="#" onclick="changeType(this,0)">字符串</a></li> <li><a href="#" onclick="changeType(this,1)">数字</a>' +
				'</li> <li><a href="#" onclick="changeType(this,2)">数组</a></li> <li><a href="#" onclick="changeType(this,3)">对象</a></li></ul></div></td><td style="text-align:center;">' +
				'<div class="input-group">      <input type="text" class="form-control" placeholder="add value" value="" name="DefaultValue">     ' +
				' <span class="input-group-btn">        <button class="btn btn-success" type="button" onclick=""><i class="fa fa-check"></i></button>   ' +
				'   </span>    </div></td><td style="text-align:center;"><div class="input-group">   ' +
				'   <input type="text" class="form-control" placeholder="add value" value="" name="ParamMock">      <span class="input-group-btn">     ' +
				'   <button class="btn btn-success" type="button" onclick=""><i class="fa fa-check"></i></button>      </span>  ' +
				'  </div></td><td style="text-align:center;"><a class="btn btn-danger btn-xs " onclick="saveNewResponse(this)" href="#">' +
				'<i class="fa fa-save"></i>保存  </a>  <a class="btn btn-danger btn-xs " onclick="removeNewResponse(this)" href="#"><i class="fa fa-remove"></i>  删除</a></td></tr>');
		}

        function addSubResponse(code){
            addNewResponse(code);
        }

		function changeType(event,type){
            $(event).parent().parent().prev().html($(event).html());
            $(event).parent().parent().prev().val(type);
		}

		function saveNewResponse(event){
			var $_enevt = $(event);
            var paramName = $_enevt.parent().parent().find('[name="ParamName"]').val();
            var paramDesc = $_enevt.parent().parent().find('[name="ParamDesc"]').val();
            var paramType = $_enevt.parent().parent().find('[name="ParamType"]').val();
            var defaultValue = $_enevt.parent().parent().find('[name="DefaultValue"]').val();
            var paramMock = $_enevt.parent().parent().find('[name="ParamMock"]').val();
            var sort =  $_enevt.parent().parent().attr('name');
            var apiProjectId = $("#apiProjectnameId").val();
            var parentResponseCode = $_enevt.parent().parent().attr('parent_code');
            var url =   prefix_response + "/addline";
            $.modal.loading("正在处理中，请稍后...");
            var data = {paramName:paramName,paramDesc:paramDesc,paramType:paramType,defaultValue:defaultValue,
                paramMock:paramMock,sort:sort,apiProjectId:apiProjectId,parentResponseCode:parentResponseCode};
            var config = {
                url: url,
                type: "post",
                data: data,
                success: function(result) {
                    $.operate.ajaxSuccess(result);
                    if (result.code == web_status.SUCCESS) {
                        searchResponse();
					}
                }
            };
            $.ajax(config)

		}

        function saveType(id,value,event) {
            $(event).parent().parent().prev().html($(event).html());
            var url =   prefix_response + "/update";
            $.modal.loading("正在处理中，请稍后...");
            var data = {value:value,responseId:id,modifyField:"ParamType"};
            var config = {
                url: url,
                type: "post",
                data: data,
                success: function(result) {
                    $.operate.ajaxSuccess(result);
                    // searchResponse();
                }
            };
            $.ajax(config)
        }

        function cleanResponse(){
            if($("#bootstrap_table_response").find("#row_id_0").length == 0){
                return;
            }
            $.modal.confirm("确定清空吗？", function() {
                var url =   prefix_response + "/clean";
                $.modal.loading("正在处理中，请稍后...");
                var data = {projectId:$("#apiProjectnameId_response").val()};
                var config = {
                    url: url,
                    type: "post",
                    data: data,
                    success: function(result) {
                        $.operate.ajaxSuccess(result);
                        searchResponse();
                    }
                };
                $.ajax(config)
            });
        }
        
		function queryResponseList(){
		 	treeTableResponse=$('#bootstrap_table_response').bootstrapTreeTable({
        		    code : 'responseCode',             // 用于设置父子关系
        	        parentCode : 'parentResponseCode', // 用于设置父子关系
        	    	type: 'get',                   // 请求方式（*）
        	        url: prefix_response+'/listtree',              // 请求后台的URL（*）
        			expandColumn : '0',            // 在哪一列上面显示展开按钮
        			striped : false,               // 是否各行渐变色
        			bordered : true,               // 是否显示边框
        			expandAll : true, // 是否全部展开
				    toolbar: '#toolbar_response',
        	        columns: [
						{
							field : 'responseId',
							title : 'ID',
                            align:'center'
						},
						// {
						// 	field : 'responseCode',
						// 	title : 'ID',
						// 	align:'center'
						// },
						// {
						// 	field : 'parentResponseCode',
						// 	title : 'ID',
						// 	align:'center'
						// },
						{
							field : 'paramName',
							title : '返回值字段',
							align:'center',
							formatter: function(value, row, index) {
								return getResponseInput(value,row.responseId,"ParamName");
							}
						},{
							field : 'paramDesc',
							title : '返回值描述',
							align:'center',
                            formatter: function(value, row, index) {
                                return getResponseInput(value,row.responseId,'ParamDesc');
                            }
						},{
							field : 'paramType',
							title : '返回值类型',
							align:'center',
							formatter: function(value, row, index) {
							    var content="";
								// var content  = $.table.selectDictLabelResponse(responseValueTypeDatas,value);
                                // content=$.table.selectDictLabel(responseValueTypeDatas, value);
                                var actions = [];
                                $.each(responseValueTypeDatas, function(index, dict) {
                                    if (dict.dictValue == value) {
                                        actions.push("<span class='badge badge-" + dict.listClass + "' data-toggle='dropdown' >" + dict.dictLabel + "</span>");
                                        return false;
                                    }
                                });
                                content =actions.join('');

								// class="btn btn-default dropdown-toggle"
							    var str ='<div class="btn-group">' +

                                        content+
                                    // '   <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> '+content+' </button>' +
                                    '  <ul class="dropdown-menu"> ' +
									' <li><a href="#" onclick="saveType('+row.responseId+',0,this)">字符串</a></li>' +
									' <li><a href="#" onclick="saveType('+row.responseId+',1,this)">数字</a></li>' +
									' <li><a href="#" onclick="saveType('+row.responseId+',2,this)">数组</a></li>' +
									' <li><a href="#" onclick="saveType('+row.responseId+',3,this)">对象</a></li></ul>'+
                                    '</div>';
								return str;
							}
						},{
							field : 'defaultValue',
							title : '默认值',
							align:'center',
                            formatter: function(value, row, index) {
                                return getResponseInput(value,row.responseId,'DefaultValue');
                            }
						},{
							field : 'paramMock',
							title : '参考值',
							align:'center',
                            formatter: function(value, row, index) {
                                return getResponseInput(value,row.responseId,'ParamMock',true);
                            }
						},{
							title: '操作',
							align: 'center',
							formatter: function(value, row, index) {
								var actions = [];
								actions.push('<a class="btn btn-success btn-xs " onclick="addSubResponse(\'' + row.responseCode + '\',this)" href="#"><i class="fa fa-plus-square"></i>新增  </a>  ');
								actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" onclick="removeResponse(\'' + row.responseCode + '\')" href="#"><i class="fa fa-remove"></i>删除</a>');
								return actions.join('');
							}
						}
					]
			});

		}


        function queryParameterList() {
            $('#bootstrap_table_parameter').bootstrapTable({
                url: prefix_parameter + "/list",
                contentType: "application/x-www-form-urlencoded",   // 编码类型
                method: 'post',                                     // 请求方式（*）
                cache: false,                                       // 是否使用缓存
                sortable: true,                                     // 是否启用排序
                sortStable: true,                                   // 设置为 true 将获得稳定的排序
                sortName: "apiParameterId",                                // 排序列名称
                sortOrder: "asc",                              // 排序方式  asc 或者 desc
                pagination: true,   // 是否显示分页（*）
                pageNumber: 1,                                      // 初始化加载第一页，默认第一页
                pageSize: 50,                                       // 每页的记录行数（*）
                pageList: [10, 25, 50],                             // 可供选择的每页的行数（*）
                iconSize: 'outline',                                // 图标大小：undefined默认的按钮尺寸 xs超小按钮sm小按钮lg大按钮
                toolbar: '#toolbar_parameter',                                // 指定工作栏
                sidePagination: "server",                           // 启用服务端分页
                search: true,           // 是否显示搜索框功能
                showRefresh: true, // 是否显示刷新按钮
                showColumns: true, // 是否显示隐藏某列下拉框
                showToggle: true,   // 是否显示详细视图和列表视图的切换按钮
                showExport: true,   // 是否支持导出文件
                queryParams: function(params) {// 查询参数设置
                    return {
                        // 传递参数查询参数
                        pageSize:       params.limit,
                        pageNum:        params.offset / params.limit + 1,
                        searchValue:    params.search,
                        orderByColumn:  params.sort,
                        isAsc:          params.order
                    }
                },
                columns: [
				{
					field : 'apiParameterId',
					title : '请求参数ID'
				},
				{
					field : 'apiProjectnameId',
					title : '所属项目ID'
				},
				{
					field : 'parameter',
					title : '参数名称'
				},
				{
					field : 'description',
					title : '参数描述'
				},
                {
                    field : 'transmissionMode',
                    title : '传参方式',
                    align: 'center',
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(paramTransmissionMode, value);
                    }
                },
				{
					field : 'defaultValue',
					title : '默认值'
				},
				{
					field : 'referenceValue',
					title : '参考值'
				},
				{
					field : 'valueType',
					title : '值类型',
                    align: 'center',
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(valueTypeDatas, value);
                    }
				},
				{
					field : 'required',
					title : '是否必填',
                    formatter: function(value, row, index) {
                        var actions = [];
                        $.each(requiredDatas, function(index, dict) {
                            if (dict.dictValue == value) {
                                actions.push("<span class='badge requiredData-" + dict.listClass + "'>" + dict.dictLabel + "</span>");
                                return false;
                            }
                        });
                        return actions.join('');
                    }
				},
				{
					field : 'createBy',
					title : '创建者'
				},
				{
					field : 'createTime',
					title : '创建时间'
				},
				{
					field : 'updateBy',
					title : '更新者'
				},
				{
					field : 'updateTime',
					title : '更新时间'
				},
				{
					field : 'remark',
					title : '备注'
				},
		        {
		            title: '操作',
		            align: 'center',
		            formatter: function(value, row, index) {
		            	var actions = [];
		            	actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="#" onclick="editParameter(\'' + row.apiParameterId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="#" onclick="removeParameter(\'' + row.apiParameterId + '\')"><i class="fa fa-remove"></i>删除</a>');
						return actions.join('');
		            }
		        }],                           // 显示列信息（*）
                responseHandler: responseHandler_parameter            // 回调函数
            });
        }

        function queryErrorcodeList() {
            $('#bootstrap_table_errorcode').bootstrapTable({
                url: prefix_errorcode + "/list",
                contentType: "application/x-www-form-urlencoded",   // 编码类型
                method: 'post',                                     // 请求方式（*）
                cache: false,                                       // 是否使用缓存
                sortable: true,                                     // 是否启用排序
                sortStable: true,                                   // 设置为 true 将获得稳定的排序
                sortName: "errorcode",                                // 排序列名称
                sortOrder: "asc",                              // 排序方式  asc 或者 desc
                pagination: true,   // 是否显示分页（*）
                pageNumber: 1,                                      // 初始化加载第一页，默认第一页
                pageSize: 10,                                       // 每页的记录行数（*）
                pageList: [10, 25, 50],                             // 可供选择的每页的行数（*）
                iconSize: 'outline',                                // 图标大小：undefined默认的按钮尺寸 xs超小按钮sm小按钮lg大按钮
                toolbar: '#toolbar_errorcode',                                // 指定工作栏
                sidePagination: "server",                           // 启用服务端分页
                search: true,           // 是否显示搜索框功能
                showRefresh: true, // 是否显示刷新按钮
                showColumns: true, // 是否显示隐藏某列下拉框
                showToggle: true,   // 是否显示详细视图和列表视图的切换按钮
                showExport: true,   // 是否支持导出文件
                queryParams: function(params) {// 查询参数设置
                    return {
                        // 传递参数查询参数
                        pageSize:       params.limit,
                        pageNum:        params.offset / params.limit + 1,
                        searchValue:    params.search,
                        orderByColumn:  params.sort,
                        isAsc:          params.order
                    }
                },
                columns: [
				{
					field : 'apiErrorcodeId',
					title : '错误代码ID'
				},
				{
					field : 'apiProjectnameId',
					title : '所属项目ID'
				},
				{
					field : 'errorcode',
					title : '错误代码编号'
				},
				{
					field : 'description',
					title : '前端提示'
				},
				{
					field : 'createBy',
					title : '创建者'
				},
				{
					field : 'createTime',
					title : '创建时间'
				},
				{
					field : 'updateBy',
					title : '更新者'
				},
				{
					field : 'updateTime',
					title : '更新时间'
				},
				{
					field : 'remark',
					title : '备注'
				},
		        {
		            title: '操作',
		            align: 'center',
		            formatter: function(value, row, index) {
		            	var actions = [];
		            	actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="#" onclick="editErrorcode(\'' + row.apiErrorcodeId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="#" onclick="removeErrorcode(\'' + row.apiErrorcodeId + '\')"><i class="fa fa-remove"></i>删除</a>');
						return actions.join('');
		            }
		        }],                           // 显示列信息（*）
                responseHandler: responseHandler_errorcode            // 回调函数
            });
        }
        

        function queryConnectorList() {

            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add/{id}",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                modalName: "接口模块",
                columns: [{
                    checkbox: true
                },
                    {
                        field : 'apiConnectorId',
                        title : '接口ID'
                    },
                    {
                        field : 'method',
                        title : '请求类型',
                        formatter: function(value, row, index) {
                                return $.table.selectDictLabel(methodDatas, value);
                        }
                    },
                    {
                        field : 'interfacename',
                        title : '接口名称'
                    },
                    {
                        field : 'description',
                        title : '接口描述'
                    },
                    {
                        title : '域名',
                        formatter: function(value, row, index) {
                            if(row.domain==undefined||row.domain==''||row.domain==null){
                                return "";
                            }
                            return row.domain.named+':'+row.domain.port+'['+row.domain.description+']';
                        }
                    },
                    {
                        field : 'urlContextpath',
                        title : '接口url路径'
                    },
                    {
                        field : 'remark',
                        title : '备注'
                    },
                    // {
                    //     field : 'createBy',
                    //     title : '创建者'
                    // },
                    // {
                    //     field : 'createTime',
                    //     title : '创建时间'
                    // },
                    {
                        field : 'updateBy',
                        title : '更新者'
                    },
                    {
                        field : 'updateTime',
                        title : '更新时间'
                    },
                    {
                        field : 'apiProjectnameId',
                        title : '所属项目ID'
                    },
                    {
                        title: '操作',
                        align: 'center',
                        formatter: function(value, row, index) {
                            var actions = [];
                            actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="#" onclick="detail( \''+row.apiConnectorId +'\', \''+row.description+'\')"><i class="fa fa-edit"></i>编辑</a> ');
                            actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="#" onclick="$.operate.remove(\'' + row.apiConnectorId + '\')"><i class="fa fa-remove"></i>删除</a>');
                            return actions.join('');
                        }
                    }]
            };
            $.table.init(options);
        }

        function queryProjectTree()
        {
            var url = ctx + "module/project/treeData";
            var options = {
                url: url,
                expandLevel: 0,
                onClick : zOnClick
            };
            $.tree.init(options);
            function zOnClick(event, treeId, treeNode) {
                reloadChildTable(treeNode)
                var stateObject = {};
                var title = "接口模块";
                var newUrl = prefix+"/uniqueid/"+treeNode.id+"/";
                window.history.pushState(stateObject,title,newUrl);

                $.getErrorGroupByProjectId(treeNode.id,function (errorGroup) {
                    if($.common.isEmpty(errorGroup)){
                        $("#errorGroup").text("错误组:[]")
                    }else{
                        $("#errorGroup").text("错误组:["+errorGroup+"]")
					}
                })
                
            }

        }

        function reloadChildTable(treeNode) {
            $("#apiProjectnameId").val(treeNode.id);
            $("#parentId").val(treeNode.pId);
            $.table.search();

            $("#apiProjectnameId_errorcode").val(treeNode.id);
            $("#parentId_errorcode").val(treeNode.pId);
            searchErrorcode();

            $("#apiProjectnameId_parameter").val(treeNode.id);
            $("#parentId_parameter").val(treeNode.pId);
            searchParameter();

 			$("#apiProjectnameId_response").val(treeNode.id);
            $("#parentId_response").val(treeNode.pId);
            searchResponse();
        }

        function searchResponse () {
		    console.log("searchResponse")
            var currentId = "response_form";
            var params = {};
            $.each($("#" + currentId).serializeArray(), function(i, field) {
                params[field.name] = field.value;
            });
            console.log(params);
            console.log(treeTableResponse);
            treeTableResponse.bootstrapTreeTable('refresh', params);
        }


        function responseHandler_parameter (res) {
            if (res.code == 0) {
                return { rows: res.rows, total: res.total };
            } else {
                $.modal.alertWarning(res.msg);
                return { rows: [], total: 0 };
            }
        }

        function responseHandler_errorcode (res) {
            if (res.code == 0) {
                return { rows: res.rows, total: res.total };
            } else {
                $.modal.alertWarning(res.msg);
                return { rows: [], total: 0 };
            }
        }

        function searchParameter() {

            var currentId = "parameter_form";
            var params = $("#bootstrap_table_parameter").bootstrapTable('getOptions');
            params.queryParams = function(params) {
                var search = {};
                $.each($("#" + currentId).serializeArray(), function(i, field) {
                    search[field.name] = field.value;
                });
                search.pageSize = params.limit;
                search.pageNum = params.offset / params.limit + 1;
                search.searchValue = params.search;
                search.orderByColumn = params.sort;
                search.isAsc = params.order;
                return search;
            }
            $("#bootstrap_table_parameter").bootstrapTable('refresh', params);
        }

        function searchErrorcode() {

            var currentId = "errorcode_form";
            var params = $("#bootstrap_table_errorcode").bootstrapTable('getOptions');
            params.queryParams = function(params) {
                var search = {};
                $.each($("#" + currentId).serializeArray(), function(i, field) {
                    search[field.name] = field.value;
                });
                search.pageSize = params.limit;
                search.pageNum = params.offset / params.limit + 1;
                search.searchValue = params.search;
                search.orderByColumn = params.sort;
                search.isAsc = params.order;
                return search;
            }
            $("#bootstrap_table_errorcode").bootstrapTable('refresh', params);
        }

        $('#btnExpand').click(function() {
            $._tree.expandAll(true);
            $(this).hide();
            $('#btnCollapse').show();
        });

        $('#btnCollapse').click(function() {
            $._tree.expandAll(false);
            $(this).hide();
            $('#btnExpand').show();
        });

        $('#btnRefresh').click(function() {
            queryProjectTree();
            positioningNode();
        });

		function openNewWindow(url) {
			//var a = $('a')[0];
			var a = $("<a href='"+url+"' target='_blank'>baidu</a>").get(0);
			var e = document.createEvent('MouseEvents');
			e.initEvent( 'click', true, true );
			a.dispatchEvent(e);
		}

        function apiview() {
			var url ="";
			var treeObj = $.fn.zTree.getZTreeObj("tree");
			//获取选中的节点
			var nodes = treeObj.getSelectedNodes();
			if (nodes.length==1)
			{
				console.log(nodes[0]);
				var id=(nodes[0].id);
				url = $.common.isEmpty(id) ? ctx + "module/project/" : ctx + "module/apiview/uniqueid/"+ id+"/";
			}else {
				url= ctx + "module/apiview/";
			}
			openNewWindow(url);
		}

        /*接口文档-接口项目*/
        function project() {
            var url ="";
            var treeObj = $.fn.zTree.getZTreeObj("tree");
            //获取选中的节点
            var nodes = treeObj.getSelectedNodes();
            if (nodes.length==1)
            {
                console.log(nodes[0]);
                var id=(nodes[0].id);
                url = $.common.isEmpty(id) ? ctx + "module/project/" : ctx + "module/project/uniqueid/"+ id+"/";
            }else {
                url= ctx + "module/project/";
            }
            createMenuItem(url, "接口项目");
        }



        /**
		 *  新增错误代码
		 **/
        function addParameter(){
            var treeObj = $.fn.zTree.getZTreeObj("tree");
            //获取选中的节点
            var nodes = treeObj.getSelectedNodes();
            if (nodes.length==1)
            {
                console.log(nodes[0]);
                var id=(nodes[0].id);
                var url = $.common.isEmpty(id) ? prefix_parameter + "/add" : prefix_parameter + "/add/"+ id;
                // window.open(url, "_blank");
                $.modal.open("添加请求参数" , url);
                // createMenuItem(url, "["+nodes[0].name+"]>新增接口");
                // $.operate.add(nodes[0].id);
            }else {
                $.modal.alertError("请先选择接口项目");
            }

		}

 			function removeResponse(id) {
           	 $.modal.confirm("确定删除该条 返回参数并删除子级 信息吗？", function() {
                var url =   prefix_response + "/remove/"+id;
                $.modal.loading("正在处理中，请稍后...");
            	var config = {
        	        url: url,
        	        type: "post",
        	        success: function(result) {
        	        	$.operate.ajaxSuccess(result);
                		searchResponse();
        	        }
        	    };
        	    $.ajax(config)
            });

        }
		function addResponse(){
			 var treeObj = $.fn.zTree.getZTreeObj("tree");
            //获取选中的节点
            var nodes = treeObj.getSelectedNodes();
            if (nodes.length==1){
                console.log(nodes[0]);
                var id=(nodes[0].id);
                var url = $.common.isEmpty(id) ? prefix_response + "/add" : prefix_response + "/add/"+ id;
                $.modal.open("按照JSON数据导入response" , url);
            }else {
                $.modal.alertError("请先选择接口项目");
            }
		}

        function editParameter(id) {
            var url =   prefix_parameter + "/edit/"+ id;
            $.modal.open("修改请求参数" , url);

        }


        function removeParameter(id) {
            $.modal.confirm("确定删除该条 请求参数 信息吗？", function() {
                var url =   prefix_parameter + "/remove";
                var data = { "ids": id };
                $.operate.submit(url, "post", "json", data);
                $("#bootstrap_table_parameter").bootstrapTable('refresh', {
                    url: prefix_parameter+"/list",
                    silent: true
                });
            });

        }

        /**
         *  新增错误代码
         **/
        function addErrorcode(){
            var treeObj = $.fn.zTree.getZTreeObj("tree");
            //获取选中的节点
            var nodes = treeObj.getSelectedNodes();
            if (nodes.length==1)
            {
                console.log(nodes[0]);
                var id=(nodes[0].id);
                var url = $.common.isEmpty(id) ? prefix_errorcode + "/add" : prefix_errorcode + "/add/"+ id;
                // window.open(url, "_blank");
                $.modal.open("添加错误代码" , url);
                // createMenuItem(url, "["+nodes[0].name+"]>新增接口");
                // $.operate.add(nodes[0].id);
            }else {
                $.modal.alertError("请先选择接口项目");
            }

        }

		function editErrorcode(id) {
            var url =   prefix_errorcode + "/edit/"+ id;

            //modal.open 点击确定后会 刷新整个页面
            $.modal.open("修改错误代码" , url);
            // var options = {
            //     url: url,
            //     title: "修改错误代码",
            //     callBack: function(index, layero) {
			// 		console.log(layero);
            //         console.log(index);
            //     }
            // };
            // $.modal.openOptions(options);

        }
        
        function removeErrorcode(id) {
            $.modal.confirm("确定删除该条 错误代码 信息吗？", function() {
                var url =   prefix_errorcode + "/remove";
                var data = { "ids": id };
                $.operate.submit(url, "post", "json", data);
                $("#bootstrap_table_errorcode").bootstrapTable('refresh', {
                    url: prefix_errorcode+"/list",
                    silent: true
                });
            });
			
        }


        /**
		 * 新增接口
         */
        function addConnector() {
            var treeObj = $.fn.zTree.getZTreeObj("tree");
            //获取选中的节点
            var nodes = treeObj.getSelectedNodes();
            if (nodes.length==1)
            {
                console.log(nodes[0]);
                var url = prefix + '/add/' + nodes[0].id;
                // window.open(url, "_blank");
                $.operate.add(nodes[0].id);
                // createMenuItem(url, "["+nodes[0].name+"]>新增接口");
                // $.operate.add(nodes[0].id);
            }else {
                $.modal.alertError("请先选择接口项目");
			}
        }

        /*接口模块列表-详细*/
        function detail(apiConnectorId,description) {
            var url = prefix + '/edit/' + apiConnectorId;
            // window.open(url, "_blank");
            // $.operate.edit(apiConnectorId);
            $.operate.editFull(apiConnectorId);

            // createMenuItem(url, "编辑["+description+"]接口");
        }


        function  copyParameter() {
            var treeObj = $.fn.zTree.getZTreeObj("tree");
            //获取选中的节点
            var nodes = treeObj.getSelectedNodes();
            if (nodes.length==1)
            {
                console.log(nodes[0]);

                var url = ctx + "module/parameterImport/copy/"+nodes[0].id;
                console.log("copyParameter.url=",url);
                $.modal.open('复制参数',url);
            }else {
                $.modal.alertError("请先选择接口项目");
            }

        }


    </script>
<script th:inline="javascript">
    $(document).ready(function () {
        var myLayout = $('body').layout({
            west_resizable:$.layout.callbacks.resizeTabLayout
		});
        var is_west_resizable = myLayout.options.west.resizable;
        console.log("is_west_resizable="+is_west_resizable);
    });


</script>
<script th:inline="javascript">
    /*<![CDATA[*/
    var id = [[${uniqueid}]];
    /*]]>*/
    if(id!=undefined){

        console.log("uniqueid="+id);
        var zTree_Menu = $.fn.zTree.getZTreeObj("tree");

        function positioningNode(){
            // console.log(zTree_Menu);
            setTimeout(function () {
                zTree_Menu = $.fn.zTree.getZTreeObj("tree");
                // console.log(zTree_Menu);
                if(zTree_Menu!=undefined){
                    var nodeList = $._tree.getNodesByParam("id",id );
                    for (var i=0, l=nodeList.length; i<l; i++) {
                        var node=nodeList[i];
                        zTree_Menu.expandNode(node, true, false, false);
                        zTree_Menu.selectNode(node,true);//指定选中ID的节点
                        reloadChildTable(node);

                    }

                }else {
                    positioningNode();
                }
            }, 1000);
        }

        positioningNode();
    }


</script>
</body>
</html>